/*
 * Copyright 2006-2011 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.krtrain.sports.options;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.krtrain.sports.team.Team;
import org.krtrain.sports.venue.Venue;
import org.kuali.rice.core.api.util.ConcreteKeyValue;
import org.kuali.rice.core.api.util.KeyValue;
import org.kuali.rice.krad.uif.view.ViewModel;
import org.kuali.rice.krad.web.form.MaintenanceForm;

/**
 * @author Kuali Rice Team (rice.collab@kuali.org)
 */
public class VenueConditionalKeyValuesFinder extends VenueKeyValuesFinder {

    @Override
    public List<KeyValue> getKeyValues(ViewModel model) {
        MaintenanceForm maintForm = (MaintenanceForm) model;
        List<KeyValue> options = new ArrayList<KeyValue>();

        Team team = ((Team) maintForm.getDocument().getNewMaintainableObject().getDataObject());
        if (team != null) {
            for (Venue venue : getAllVenues()) {
                if (StringUtils.equals(venue.getStateCode(), team.getStateCode())) {
                    options.add(new ConcreteKeyValue(venue.getId(), venue.getName()));
                }
            }

        }

        return options;
    }

}
